package com.jxc.jxc01.hch.service.Impl;


import com.jxc.jxc01.hch.dao.Impl.UserDaoImpl;
import com.jxc.jxc01.hch.dao.UserDao;
import com.jxc.jxc01.hch.entity.PageHelper;
import com.jxc.jxc01.hch.entity.User;
import com.jxc.jxc01.hch.service.IUserService;

import java.text.SimpleDateFormat;
import java.util.Date;

public class IUserServiceImpl implements IUserService {
    UserDao userDao = new UserDaoImpl();
    @Override
    public PageHelper<User> list(PageHelper<User> pageHelper) {
        userDao.list(pageHelper);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public PageHelper<User> query(PageHelper<User> pageHelper, String username) {
        userDao.query(pageHelper,username);
        int pageCount = (pageHelper.getTotal()%pageHelper.getPageSize())==0?pageHelper.getTotal()/pageHelper.getPageSize():pageHelper.getTotal()/pageHelper.getPageSize()+1;
        pageHelper.setPageCount(pageCount);
        return pageHelper;
    }

    @Override
    public int increase(User user) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //接收时间日期
        String s = sdf.format(date);
        user.setCreationtime(s);
        return userDao.increase(user);
    }

    @Override
    public int modify(User user) {
        return userDao.modify(user);
    }

    @Override
    public int delete(int id) {
        return userDao.delete(id);
    }

    @Override
    public int reductionPassword(int id) {
        return userDao.reductionPassword(id);
    }

    @Override
    public int role(int id, String power) {
        return userDao.role(id,power);
    }
}
